<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
            <el-form-item label="物料名称">
                <el-input v-model="queryParams.recoderName" placeholder="请输入物料名称" clearable/>
            </el-form-item>
            <el-form-item label="物料编号">
                <el-input v-model="queryParams.recoderNo" placeholder="请输入物料编号" clearable/>
            </el-form-item>
            <el-form-item label="任务编号">
                <el-input v-model="queryParams.taskNo" placeholder="请输入任务编号" clearable/>
            </el-form-item>

            <el-form-item label="时间">
                <el-date-picker
                    v-model="dateRange"
                    style="width: 215px"
                    value-format="yyyy-MM-dd"
                    type="daterange"
                    range-separator="-"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                ></el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <div class="mb8">
            <el-button type="success" plain icon="el-icon-download" size="mini" @click="onExport">导出数据</el-button>
        </div>
        <el-table v-loading="loading" :data="tableList">
            <el-table-column label="时间" prop="recoderDate" width="170"/>
             <el-table-column label="库存类型" prop="categoryName" show-overflow-tooltip/>
              <el-table-column label="供应商信息" prop="manuFactor" show-overflow-tooltip/>
            <el-table-column label="物料名称" prop="recoderName" show-overflow-tooltip/>
            <el-table-column label="物料编号" prop="recoderNo" show-overflow-tooltip/>
            <el-table-column label="规格" prop="recoderSku" show-overflow-tooltip/>
             <el-table-column label="颜色" prop="colour" show-overflow-tooltip/>
            <el-table-column label="修改数量" prop="recoderChanage" show-overflow-tooltip/>
            <el-table-column label="操作" prop="recoderReason" show-overflow-tooltip/>
            <el-table-column label="经办人" prop="recoderOpter" show-overflow-tooltip/>
            <el-table-column label="关联任务编号" prop="taskNo" show-overflow-tooltip/>
            <el-table-column label="操作" width="100" class-name="small-padding fixed-width">
                <template slot-scope="{row}">
                    <!-- <el-button size="mini" type="text" @click="handleDetail(row)">详情</el-button> -->
                    <el-button size="mini" type="text" @click="handleAdd(row)">详情</el-button>
                     </template>
            </el-table-column>
        </el-table>
        <!-- 添加或修改用户配置对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="600px" style="padding-top: 3rem;" append-to-body>
            <el-form ref="detailData" :model="detailData" label-width="100px">
            <el-row>
              <el-col :span="12">
                <el-form-item label="修改数量" prop="recoderChanage">
                  <el-input v-model="detailData.recoderChanage" disabled="true" maxlength="30" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="供应商信息" prop="manuFactor">
                  <el-input v-model="detailData.manuFactor" disabled="true" maxlength="200" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="修改原因" prop="recoderReason">
                  <el-input v-model="detailData.recoderReason" disabled="true" maxlength="300" />
                </el-form-item>
              </el-col>
            </el-row>
            </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="cancel">取 消</el-button>
          </div>
        </el-dialog>
        <!--分页-->
        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                    @pagination="getList"/>
    </div>
</template>

<script>
import {responseEnum} from "../../../const/const";
import {getMaterialStoreList} from "./api";

export default {
      name: "/materialStore/record",
    data() {
        return {
            // 是否显示弹出层
            open: false,
            // 弹出层标题
            title: "",
            // 日期范围
            dateRange: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                recoderName: null,
                recoderNo: null,
                taskNo: null
            },
            // 遮罩层
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            tableList: [],
            detailData:{}
        };
    },
    created() {
        this.getList();
    },
    methods: {
        /** 新增按钮操作 */
        handleAdd(row) {
              this.detailData=row;
          this.resetQuery();
          this.open = true;
          this.title = "库存记录详情";
          this.$forceUpdate()
          // getUser().then(response => {
          //   this.postOptions = response.posts;
          //   this.roleOptions = response.roles;
          //   this.open = true;
          //   this.title = "添加用户";
          //   this.form.password = this.initPassword;
          // });
        },
        // 取消按钮
        cancel() {
          this.open = false;
          this.resetQuery();
        },
        //详情
        handleDetail(row) {
            this.$router.push({
                path: '/stockRecoder/detail',
                query: {detailData: row}
            });
        },

        /** 查询列表 */
        getList() {
            this.loading = true;
            getMaterialStoreList(this.addDateRange(this.queryParams, this.dateRange)).then(res => {
                if (res.code === responseEnum.success) {
                    this.tableList = res.rows || [];
                    this.total = res.total || 0;
                }
            }).finally(() => this.loading = false);
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = [];
            this.queryParams = this.$options.data().queryParams;
            this.handleQuery();
        },
        /**
         * 导出
         */
        onExport() {
            this.download('dataManager/export', this.queryParams, `物料库存_${new Date().getTime()}.xlsx`)
        }
    }
};

</script>

<style lang="scss" scoped>

</style>
